/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.Actions;

import dao.EnterpriseDAO;

import java.io.Serializable;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Enterprise;
import model.Erro;
import model.User;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Adriano
 */
public class SearchAllEnterpriseAction extends Action implements Serializable {
	
	final static Logger logger = Logger.getLogger(SearchAllEnterpriseAction.class);

    @Override
    public ActionForward execute(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        try {
            User user = (User) request.getSession().getAttribute("User");
            if (user == null) {
                return mapping.findForward("erroAlias");
            }
            
           
            
//            if (user.profile(user.getLstprofile())) {
//                request.getSession().setAttribute("ErroMSG", Erro.erroMsg[Erro.SEM_PERMISSAO]);
//                return mapping.findForward("semPermissaoAlias");
//            
        else {
                EnterpriseDAO eDAO = new EnterpriseDAO();
                
                ArrayList<Enterprise> listEmpresa = (ArrayList<Enterprise>) eDAO.findAll();
                eDAO.closeDAO();
                request.getSession().setAttribute("ListEmpresa", listEmpresa);
                return mapping.findForward("relEmpresaAllAlias");
            }

    }
    catch(Exception e

    
        ) {
    	logger.error("FINDALLEMPRESA.execute() " ,e);
    	
        return mapping.findForward("erroAlias");

    }

}

}
